#include <stdio.h>
#include <stdlib.h>
#include "sorts.h"
 
#define SWAP(T,a,b)  {T t=a; a=b; b=t; }

void bubble_sort(ELE_TYPE arr[], int len)
{
	int i, j; 
	BOOL changed;
 
	for (i=len-1;i>0;i--)
	{
		changed=FALSE;
		for (j=0;j<i;j++)
		{
			if (arr[j] > arr[j + 1])
			{
				changed=TRUE;
				SWAP(ELE_TYPE,arr[j], arr[j+1])
			}
		}
		if ( !changed)
			break;
	}
 
}
 
void test_bubble_sort()
{
	ELE_TYPE arr[] = { 61, 17, 29, 22, 34, 60, 72, 21, 50, 1, 62 };
	int len = (int) sizeof(arr) / sizeof(arr[0]);
	
	printf("Original data are:");
	print_array(arr, len);
 
	bubble_sort(arr, len);
	printf("The data after sorted are:");
	print_array(arr, len);	
	
}
